package com.danger.Presenter;

import android.content.Context;

import com.danger.Model.action.ForgetPasswordModel;
import com.danger.Model.action.ForgetPasswordModelImpl;
import com.danger.Model.listener.OnVerifyListener;
import com.danger.View.ForgetPasswordView;

/**
 * Created by danger on 2016/4/5.
 */
public class ForgetPasswordPresenterImpl implements ForgetPasswordPresenter {

    private Context context;
    private ForgetPasswordModel model;
    private ForgetPasswordView view;

    public ForgetPasswordPresenterImpl(Context context, ForgetPasswordView view) {
        this.context = context;
        this.view = view;
        model = new ForgetPasswordModelImpl(context);
    }

    @Override
    public void verifyByEmail(String email) {
        String msg = model.check(email);
        if (msg.equals("正确")) {
            view.showDialog();
            model.resetPassword(email, new OnVerifyListener() {
                @Override
                public void onSuccess() {
                    view.hideDialog();
                    view.showSuccess();
                }

                @Override
                public void onError(String error) {
                    view.hideDialog();
                    view.showError(error);
                }
            });
        } else {
            view.showError(msg);
        }
    }

}
